from database.models import Videos, Video_details, Users

# 请修改此地方参数
server_ip = 'http://s3hdmp00b.hn-bkt.clouddn.com/'  # 例子，运行需要根据内容修改
type_folder = {'1': 'geek/', '2': 'entertainment/'}  # 例子，运行需要根据内容修改
baidu_access_token = "需要填写"


def get_banner_details(object: Videos):
    if object.video_cover is not None:
        return {'id': object.video_id, 'name': object.name, 'poster': object.video_cover, 'url': object.url}
    return {'id': object.video_id, 'name': object.name,
            'poster': f'{server_ip}{type_folder[str(object.video_type)]}{object.name}_shot.jpg',
            'url': f'{server_ip}{type_folder[str(object.video_type)]}{object.name}.mp4'}


def get_more_details(object: Videos, user_id: int):
    user_obj = Users.objects.filter(user_id=user_id).first()
    return {'name': object.name, 'describe': object.describe, 'author': object.author.user_name,
            'like': len(Video_details.objects.filter(video__video_id=object.video_id, operation_type=1)),
            'unlike': len(Video_details.objects.filter(video__video_id=object.video_id, operation_type=2)),
            'share': len(Video_details.objects.filter(video__video_id=object.video_id, operation_type=3)),
            'fav': len(Video_details.objects.filter(video__video_id=object.video_id, operation_type=4)),
            'is_like': bool(
                Video_details.objects.filter(user=user_obj, operation_type=1).first()) if user_obj else False,
            'is_unlike': bool(
                Video_details.objects.filter(user=user_obj, operation_type=2).first()) if user_obj else False,
            'is_fav': bool(
                Video_details.objects.filter(user=user_obj, operation_type=4).first()) if user_obj else False}
